package com.example.lizhanqi.livevideo.presenter;

import com.example.lizhanqi.livevideo.bean.PhLoginBean;
import com.example.lizhanqi.livevideo.contacts.ContactAddress;
import com.example.lizhanqi.livevideo.model.net.Networking;
import com.example.lizhanqi.livevideo.utils.PhoneUtils;
import com.example.lizhanqi.livevideo.view.IPhLoginUI;
import com.yolanda.nohttp.Logger;
import com.yolanda.nohttp.rest.RequestQueue;
import com.yolanda.nohttp.rest.Response;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Lizhanqi on 2016/9/19 0019.
 */
public class PhLogin implements ILoginPresnter {
    IPhLoginUI ipui;
    private final Networking lastedNet;

    public PhLogin(IPhLoginUI ipui) {
        this.ipui = ipui;
        lastedNet = new Networking(this);
    }

    public boolean checkphone(PhLoginBean pb) {
        String s = pb.getPhone().replaceAll("\\s", "");
        return PhoneUtils.isPhoneNumber(s);
    }

    public void sendCode(String uri, PhLoginBean phLoginBean, RequestQueue requestQueues, int what) {
        Map<String, String> stringStringHashMap = new HashMap<String, String>();
        stringStringHashMap.put("phone", phLoginBean.getPhone());
        lastedNet.requestPOST(uri, requestQueues, what, stringStringHashMap);
    }

    public void resqustLogin(String uri, PhLoginBean phLoginBean, RequestQueue requestQueues, int what) {
        Map<String, String> stringStringHashMap = new HashMap<String, String>();
        stringStringHashMap.put("phone", phLoginBean.getPhone());
        stringStringHashMap.put("code", phLoginBean.getChecknumber());
        stringStringHashMap.put("r", ContactAddress.Rid);
        stringStringHashMap.put("sign", ContactAddress.SIGN);
        lastedNet.requestPOST(uri, requestQueues, what, stringStringHashMap);
    }
    @Override
    public void ok(Response<String> response, int what) {
        Logger.i(response.get());
        ipui.ok(what, "");
    }

    @Override
    public void error(int i, String s, Object o, Exception e, int i1, long l) {
    }

    @Override
    public void sendfinsh() {

    }
}
